package com.example.security.handler;

import com.example.security.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.web.authentication.logout.LogoutHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 注销登录操作回调
 */
@Component
public class AppLogoutHandler implements LogoutHandler {
    @Autowired
    private UserMapper userMapper;

    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {

        Object principal = authentication.getPrincipal();

        if (principal instanceof User) {

        }

//
//        com.example.security.entity.User user1 = userMapper.findByUserName(user.getUsername());
//        //账户被禁用
//        user1.setEnabled(false);
//        userMapper.updateUserById(user1);

    }
}
